package com.example.nongye.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.example.nongye.R;
import com.example.nongye.databinding.ActivityBillDetailBinding;
import com.example.nongye.http.api.BillListApi;
import com.example.nongye.utils.StringUtils;
import com.jaeger.library.StatusBarUtil;
import com.tencent.mmkv.MMKV;


public class BillDetailActivity extends AppCompatActivity {

    private ActivityBillDetailBinding binding;

    private BillListApi.Response response;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityBillDetailBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        StatusBarUtil.setColor(this, getResources().getColor(R.color.white), 0);
        StatusBarUtil.setLightMode(this);

        binding.btnBack.setOnClickListener(view -> finish());

        response = getIntent().getExtras().getParcelable("detail");

        binding.btnBack.setOnClickListener(view -> finish());
        initDate();
    }

    private void initDate() {
        String card = MMKV.defaultMMKV().getString("card", "");
        if ((!TextUtils.isEmpty(card) && card.length() > 5)) {
            binding.tvCard.setText(card.substring(0, 4) + " **** " + card.substring(card.length() - 4));
        }
        if (null != response.getAmount()) {
            if (response.getAmount() > 0) {
                binding.tvAmount.setTextColor(getResources().getColor(R.color.colorAccent));
                binding.tvAmount.setText("+" + StringUtils.numberFormat(response.getAmount()));
            } else {
                binding.tvAmount.setTextColor(getResources().getColor(R.color.color_333));
                binding.tvAmount.setText(StringUtils.numberFormat(response.getAmount()));
            }
        }
        if (!TextUtils.isEmpty(response.getCreateDate())) {
            binding.tvJiaoyishijian.setText(response.getCreateDate().replace("T", " "));
        }
        if (!TextUtils.isEmpty(response.getItem())) {
            binding.tvJiaoyizhaiyao.setText(response.getItem());
            //转支是收款方 收款账户 收款银行
            //转存是付款方 付款账户 付款银行；
            if (TextUtils.equals(response.getItem(), "转存")) {
                binding.titleFukuanfang.setText("付款方");
                binding.tvFukuanzhanghu.setText("付款账户");
                binding.titleFkyh.setText("付款银行");
                binding.layoutFkyh.setVisibility(View.VISIBLE);
                binding.tvFkyh.setText("哈尔滨银行");
            } else if (TextUtils.equals(response.getItem(), "转支")) {
                binding.titleFukuanfang.setText("收款方");
                binding.titleFukuanzhanghu.setText("收款账户");
                binding.titleFkyh.setText("收款银行");
                binding.layoutFkyh.setVisibility(View.VISIBLE);
                if (!TextUtils.isEmpty(response.getOtherAccountBank())) {
                    binding.tvFkyh.setText(response.getOtherAccountBank());
                }
            } else {
                binding.layoutFkyh.setVisibility(View.GONE);
                binding.titleFukuanfang.setText("付款方");
                binding.titleFukuanzhanghu.setText("付款账户");
            }
        }
        if (!TextUtils.isEmpty(response.getOtherAccountName())) {
            binding.tvFukuanfang.setText(response.getOtherAccountName());
        }
        if (!TextUtils.isEmpty(response.getOtherAccount())) {
            binding.tvFukuanzhanghu.setText(response.getOtherAccount());
        }

        //TODO 缺少交易类型
        binding.tvJiaoyileixing.setText("转账");
        if (!TextUtils.isEmpty(response.getTransactionChannel())) {
            binding.tvJiaoyiqudao.setText(response.getTransactionChannel());
        }
        if (null != response.getBalance()) {
            binding.tvBenciyue.setText(StringUtils.double2Str(response.getBalance()));
        }
        binding.tvJiaoyifuyan.setText("---");

    }


}